home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / timeline / zoom.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-15  |  6.8 KB  |  184 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/TimeLine/RCS/zoom.c,v 1.1 91/10/02 16:11:16 chua Exp Locker: drapeau $ */
  25. /* $Log:    zoom.c,v $
  26.  * Revision 1.1  91/10/02  16:11:16  chua
  27.  * In ZoomSliderNotify, change the values in the grid menu so that the 
  28.  * correct time interval is displayed.  It is now in terms of mins and secs, 
  29.  * instead of pixels.
  30.  * 
  31.  * Revision 1.0  91/09/30  17:03:13  chua
  32.  * Update to version 1.0
  33.  * 
  34.  * Revision 0.45  91/08/05  13:07:50  chua
  35.  * When calculting the canvas start, instead of using the number 50, use the constants,
  36.  * TimeLineInterval and PixelsPerSecond to arrive at the number instead.
  37.  * 
  38.  * Revision 0.44  91/07/17  14:36:59  chua
  39.  * When zooming is done, set the time of the starting canvas position of the new zoomed
  40.  * display to be approximately the same as that of the starting position prior to
  41.  * zooming.
  42.  * 
  43.  * Revision 0.43  91/07/17  10:40:28  chua
  44.  * In the ZoomSliderNotify procedure, there is no need to draw the playback head, as
  45.  * this is taken care of in the call to ShowNewCanvas, which replaces the call to
  46.  * RepaintCanvas (there is no need to redraw the AppCanvas).
  47.  * 
  48.  * Revision 0.42  91/07/09  17:03:24  chua
  49.  * In the definition of ZoomSliderNotify, make it return an integer, to be
  50.  * consistent with what Guide generated.
  51.  * 
  52.  * Revision 0.41  91/06/26  16:55:36  chua
  53.  * no changes
  54.  * 
  55.  * Revision 0.40  91/06/24  13:21:59  chua
  56.  * This file contains the zoom notify routine for the zoom slider found
  57.  * in the TimeLine Editor main window.
  58.  *  */
  59.  
  60. static char zoomrcsid[] = "$Header: /Source/Media/collab/TimeLine/RCS/zoom.c,v 1.1 91/10/02 16:11:16 chua Exp Locker: drapeau $";
  61.  
  62. #include "main.h"
  63.  
  64. /*
  65.  * Notify callback function for `ZoomSlider'.
  66.  * This function will zoom the display to the level indicated on the zoom slider.
  67.  * It will set the canvas start position so that the new zoomed display will start from approximately the same time (which might be slightly off due to
  68.  * rounding errors).
  69.  * It will also change the entries in the grid menu so that the correct time intervals are displayed.
  70.  */
  71. int ZoomSliderNotify(item, value, event)
  72.      Panel_item        item;
  73.      int        value;
  74.      Event        *event;
  75. {
  76.   int viewStart;
  77.   int oldcanvasStart;
  78.   int gridValue, gridMin;
  79.   int previousZoomLevel;
  80.   int i;
  81.   static char **buf;
  82.   char *bufmin, *bufsec;
  83.   Menu menu;
  84.   Menu_item mi[5];
  85.   TimeLineFramePtr tlFrame;
  86.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  87.  
  88.   tlFrame = TimeLineWindow[xv_get(ip->controls, PANEL_CLIENT_DATA)];
  89.   bufsec = (char *) malloc(20);
  90.   bufmin = (char *) malloc(20);
  91.   buf = (char **) malloc (sizeof (char *) * 6);
  92.   for (i = 0; i <= 5; i++) 
  93.     buf[i] = (char *) malloc(40);
  94.   viewStart = (int) xv_get(tlFrame->DrawScrollbarVer, SCROLLBAR_VIEW_START);
  95.   oldcanvasStart = (tlFrame->canvasStart + viewStart) * tlFrame->zoomLevel; /* Get the previous canvas starting position */
  96.   previousZoomLevel = tlFrame->zoomLevel;
  97.   tlFrame->zoomLevel = xv_get(item, PANEL_VALUE);            /* Get the new zoom level */
  98.   menu = xv_get(tlFrame->TimeLine_window->optionsButton, PANEL_ITEM_MENU);
  99.   gridValue = previousZoomLevel / 2;                    /* Find the menu item for the 5 pixels grid spacing */
  100.   if (previousZoomLevel == 1) 
  101.     sprintf(bufsec, "1/2");
  102.   else if (previousZoomLevel%2 == 0)
  103.     sprintf(bufsec, "%d", gridValue);
  104.   else
  105.     sprintf(bufsec, "%d 1/2", gridValue);
  106.   if (previousZoomLevel > 2)
  107.     sprintf (buf[0], "%s seconds", bufsec);
  108.   else
  109.     sprintf (buf[0], "%s second", bufsec);
  110.   mi[0] = (Menu_item) xv_find (menu, MENUITEM,
  111.                 MENU_STRING, buf[0],
  112.                 NULL);
  113.   for (i=1; i <= 5; i++)                        /* Find the menu item for the 10, 20, 30, 40 and 50 pixels grid spacing items */
  114.   {
  115.     gridValue = previousZoomLevel * i;                    /* Find the menu item for the 10 pixels grid spacing */
  116.     gridMin = 0;
  117.     while (gridValue >= 60)                        /* Convert to minutes and seconds if necessary */
  118.     {
  119.       gridValue -= 60;
  120.       gridMin ++;
  121.     }
  122.     if (gridMin > 1)
  123.       sprintf(bufmin, "%d minutes", gridMin);
  124.     else
  125.       sprintf(bufmin, "%d minute", gridMin);
  126.     if (gridValue > 1)
  127.       sprintf(bufsec, "%d seconds", gridValue);
  128.     else
  129.       sprintf(bufsec, "%d second", gridValue);
  130.     if (gridMin > 0) 
  131.       sprintf (buf[i], "%s %s", bufmin, bufsec);
  132.     else
  133.       strcpy (buf[i], bufsec);
  134.     mi[i] = (Menu_item) xv_find (menu, MENUITEM,
  135.                    MENU_STRING, buf[i],
  136.                    NULL);
  137.   }
  138.   gridValue = tlFrame->zoomLevel / 2;                    /* Set the menu item for the 5 pixels grid spacing */
  139.   if (tlFrame->zoomLevel == 1) 
  140.     sprintf(bufsec, "1/2");
  141.   else if (tlFrame->zoomLevel%2 == 0)
  142.     sprintf(bufsec, "%d", gridValue);
  143.   else
  144.     sprintf(bufsec, "%d 1/2", gridValue);
  145.   if (tlFrame->zoomLevel > 2) 
  146.     sprintf (buf[0], "%s seconds", bufsec);
  147.   else
  148.     sprintf (buf[0], "%s second", bufsec);
  149.   xv_set(mi[0], MENU_STRING, buf[0], NULL);
  150.   for (i=1; i <= 5; i++)                        /* Set the menu item for the 10, 20, 30, 40 and 50 pixels grid spacing items */
  151.   {
  152.     gridValue = tlFrame->zoomLevel * i;                    /* Set the menu item for the 10 pixels grid spacing */
  153.     gridMin = 0;
  154.     while (gridValue >= 60)                        /* Convert to minutes and seconds if necessary */
  155.     {
  156.       gridValue -= 60;
  157.       gridMin ++;
  158.     }
  159.     if (gridMin > 1)
  160.       sprintf(bufmin, "%d minutes", gridMin);
  161.     else
  162.       sprintf(bufmin, "%d minute", gridMin);
  163.     if (gridValue > 1)
  164.       sprintf(bufsec, "%d seconds", gridValue);
  165.     else
  166.       sprintf(bufsec, "%d second", gridValue);
  167.     if (gridMin > 0) 
  168.       sprintf (buf[i], "%s %s", bufmin, bufsec);
  169.     else
  170.       strcpy (buf[i], bufsec);
  171.     xv_set(mi[i], MENU_STRING, buf[i], NULL);
  172.   }
  173.   tlFrame->canvasStart = oldcanvasStart / tlFrame->zoomLevel;
  174.   tlFrame->canvasStart = tlFrame->canvasStart - tlFrame->canvasStart % (TimeLineInterval * PixelsPerSecond); 
  175.   ShowNewCanvas(tlFrame, 1);
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.